package org.scirp.ijmis.dao.review.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.scirp.ijmis.dao.base.impl.BaseDAOImpl;
import org.scirp.ijmis.dao.review.IReleasedCommentDAO;
import org.scirp.ijmis.po.review.ReleasedComment;
import org.scirp.ijmis.po.review.ReviewPaper;

public class ReleasedCommentDAOImpl extends BaseDAOImpl<ReleasedComment> implements IReleasedCommentDAO {

	private static final String className = ReleasedCommentDAOImpl.class.toString();

	public ReleasedComment selectById(Object id) {

		return (ReleasedComment) super.selectById(id, className + "-->selectById");
	}

	public List<ReleasedComment> selectCommentByPaperID(long paperID) {
		String hql = "from ReleasedComment where paper.pid=:paperID and isReleased='true' ";

		Map<String, Long> parameters = new HashMap<String, Long>();
		parameters.put("paperID", paperID);

		return super.ExecuteQuery(hql, parameters, className + "-->selectCommentByPaperID(long paperID)");

	}

	public List<ReleasedComment> selectAll() {

		String hql = "from ReleasedComment order by pid desc";
		return super.ExecuteQuery(hql, className + "-->selectAll");
	}

	public Long countObject() {
		return super.countObject(className + "-->selectAll");
	}

	public Long saveReleasedComment(ReleasedComment releasedComment) {
		return super.saveObject(releasedComment, className + "-->saveReleasedComment");
	}

	public boolean updateReleasedComment(ReleasedComment releasedComment) {
		return super.updateObject(releasedComment, className + "-->updateReleasedComment");
	}

	public List<ReleasedComment> selectByPaperId(Long paperId) {
		String hql = "from ReleasedComment where paper.pid=:paperId";
		Map<String, Long> map = new HashMap<String, Long>();
		map.put("paperId", paperId);
		return super.ExecuteQuery(hql, map, className + "-->selectByPaperId(Long paperId)");
	}

	public boolean deleteReleasedComment(Long releasedCommentId) {
		String hql = "delete from ReleasedComment where pid=:pid";
		Map<String, Long> parameter = new HashMap<String, Long>();
		parameter.put("pid", releasedCommentId);
		return super.ExecuteNonQuery(hql, parameter, className + "-->deleteReleasedComment(Long releasedCommentId)");
	}

	public ReleasedComment selectByPaperIdAndPersonId(Long paperId, Long personId) {
		String hql = "from ReleasedComment where paper.pid=:paperId and person.pid=:personId";
		Map<String, Long> parameter = new HashMap<String, Long>();
		parameter.put("paperId", paperId);
		parameter.put("personId", personId);
		return (ReleasedComment) super.selectSingle(hql, parameter, className + "-->selectByPaperIdAndPersonId(Long paperId, Long personId)");
	}

}
